package com.example.mypotiota_si.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypotiota_si.Datas.Dianpu;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

public class ListViewAdapter_wm_dp extends RecyclerView.Adapter<ListViewAdapter_wm_dp.ViewHolder> {
    ArrayList<Dianpu> dianpu;
    Context context;

    public ListViewAdapter_wm_dp(ArrayList<Dianpu> dianpu, Context context) {
        this.dianpu = dianpu;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wm_dp_list_view,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.setData(dianpu.get(position));
    }

    @Override
    public int getItemCount() {
        if (dianpu!=null){
            return dianpu.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView name,pf,ys,sj,qs;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.wm_dp_icon);
            name=itemView.findViewById(R.id.wm_dp_name);
            pf=itemView.findViewById(R.id.wm_dp_pf);
            ys=itemView.findViewById(R.id.wm_dp_ys);
            sj=itemView.findViewById(R.id.wm_dp_sj);
            qs=itemView.findViewById(R.id.wm_dp_qs);
        }

        public void setData(Dianpu dianpu) {
            icon.setImageResource(dianpu.dp_icon);
            name.setText(dianpu.dp_name);
            pf.setText("评分"+dianpu.dp_pf);
            ys.setText("|月售"+dianpu.dp_ys);
            sj.setText(dianpu.dp_sj);
            qs.setText(dianpu.dp_qs);
        }
    }
}
